package com.hy.frame.ui

import android.view.View
import androidx.lifecycle.LifecycleObserver

/**
 * title 无
 * author heyan
 * time 19-3-8 下午2:07
 * desc 无
 */
interface IImageLoader {
    fun load(v: View, url: String?)
    /**
     * @param v 如果是 ImageView 设置src，否则 background
     */
    fun load(v: View, info: ImageInfo)

    fun onDestroy()
    /**
     * 请使用GenericLifecycleObserver
     */
    fun getLifecycleObserver(): LifecycleObserver

    class ImageInfo {
        var url: String? = null
        var loading: Int = 0
        var fail: Int = 0
        var isGif: Boolean = false
        var listener: ILoadListener? = null

        constructor(url: String?) {
            this.url = url
        }

        constructor(url: String?, loading: Int = 0, fail: Int = 0, isGif: Boolean = false) {
            this.url = url
            this.loading = loading
            this.fail = fail
            this.isGif = isGif
        }

        companion object {
            fun create(url: String?): ImageInfo = ImageInfo(url)
        }
    }

    interface ILoadListener {
        fun onLoading(v: View)
        fun onLoadComplete(v: View, obj: Any?)
    }
}